//记分牌
export default class ScorePanel {
  score = 0; //分数
  level = 1; //等级
  scoreEle: HTMLElement;
  levelEle: HTMLElement;
  /**最大等级**/
  maxLevel: number;
  /**多少分升一级**/
  upScore: number;

  constructor(maxLevel: number = 10, upScore: number = 2) {
    this.scoreEle = document.getElementById("score")!;
    this.levelEle = document.getElementById("level")!;
    this.upScore = upScore;
    this.maxLevel = maxLevel;
  }

  //增加分数
  addScore() {
    this.scoreEle.innerHTML = ++this.score + "";
    //每10分回升一级
    if (this.score % this.upScore == 0) {
      this.levelUp();
    }
  }

  levelUp() {
    if (this.level < this.maxLevel) {
      this.levelEle.innerHTML = ++this.level + "";
    }
  }
}
